package com.group.service.impl;

import com.group.mapper.AddressMapper;
import com.group.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import pojo.entity.Address;
import pojo.qo.AddressState;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public int addAddress(Address address) {
        return addressMapper.addAddress(address);
    }

    @Override
    public int deleteByAddressId(Long addressId) {
        return addressMapper.deleteByAddressId(addressId);
    }

    /*@Override
    public void updateAddress(Address address) {
        addressMapper.updateAddress(address);
    }*/

    @Override
    public List<Address> queryByUserIdGetAllAddress(Long userId) {
        return addressMapper.queryByUserIdGetAllAddress(userId);
    }

    @Override
    public Address queryByUserIdForDefault(Long userId) {
        return addressMapper.queryByUserIdForDefault(userId);
    }

    @Override
    public Address queryByAddressId(Long addressId) {
        return addressMapper.queryByAddressId(addressId);
    }

    @Override
    public void addressToDefault(AddressState address) {
        addressMapper.addressToDefault(address);
        addressMapper.addressToNoDefault(address);
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate(new OkHttp3ClientHttpRequestFactory());
    }
}
